﻿package com.eve.microworld.main;

import android.content.Context;
import android.os.Bundle;

import com.eve.microworld.R;
import com.eve.microworld.common.activity.BaseActivity;
import com.eve.microworld.common.app.Constants;
import com.eve.microworld.common.tools.ComTimeTools;
import com.eve.microworld.common.tools.ConfigurationTools;
import com.eve.microworld.common.tools.LogTools;

/**
 * 登录界面
 * 
 * @author Norsie
 * 
 */
public class LoginActivity extends BaseActivity
{

    private Context mContext = LoginActivity.this;

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login_main);

        // 检查是否已经记住登陆
        if (checkLoginState())
        {
            gotoActivityAndFinish(mContext, HomeAcitvity.class);
        }
        else
            login();
    }

    private void login()
    {
        // TODO Auto-generated method stub

    }

    private boolean checkLoginState()
    {
        // TODO Auto-generated method stub
        if (ConfigurationTools.getInstance(mContext).getString(
                Constants.LOGIN_STATE, "false").equals("false"))
            return false;
        else
        {

            String days = ComTimeTools.getTimeDiff(
                    ConfigurationTools.getInstance(mContext).getString(
                            Constants.REMEMBER_PASSWD_TIME),
                    ComTimeTools.getTime("yyyy-MM-dd HH:mm:ss"));

            LogTools.info("自动登陆天数：" + days);
            // 当自动登陆超过7天时，要求重新登陆。
            if (Integer.parseInt(days) > 7)
                return false;
            else
                return true;

        }
    }

}
